package com.bdqn.t350.proxy;

import com.bdqn.t350.dao.UserDao;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class IntermediaryImp implements InvocationHandler {
    //被代理对象--刘德华
    private Object target;

    public IntermediaryImp(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        before();    //target.method(args)            user.add(100);
        Object msg = method.invoke(target, args);   //add.invoke(user,100)
        after();
        return msg;
    }

    public void before() {
        System.out.println("之前");
    }

    public void after() {
        System.out.println("之后");
    }
}
